package com.nowcoder.event;

import com.alibaba.fastjson.JSONObject;
import com.nowcoder.entity.Event;
import com.nowcoder.util.CommunityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * @author by lvshh
 * @version 1.0
 * @date 2020/5/5 8:25
 */
@Component
public class EventProducer {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    //处理事件

    public void fireEvent(Event event){

        //将事件发布到指定的主题
        kafkaTemplate.send(event.getTopic(), JSONObject.toJSONString(event));

    }
}
